﻿using System;
using System.Collections.Generic;
using System.Linq;
using MQuery;
using SW.DDD.Domain;

namespace SW.DDD.Application.Query
{
    /// <summary>
    /// 统一查询参数
    /// </summary>
    /// <typeparam name="TView">要返回的视图类型</typeparam>
    /// <typeparam name="TEntity">来源的实体类型</typeparam>
    /// <typeparam name="TKey">实体的键类型</typeparam>
    public class Query<TView, TEntity, TKey> : IQuery<(IEnumerable<TView> data, int? count)>
        where TEntity : class, IAggregateRoot<TKey>
        where TKey : notnull
    {
        /// <summary> </summary>
        /// <param name="queryExpression">查询表达式</param>
        /// <param name="needCount">是否计数</param>
        public Query(QueryExpression<TView> queryExpression, bool needCount = false)
        {
            QueryExpression = queryExpression;
            NeedCount = needCount;
        }

        public QueryExpression<TView> QueryExpression { get; }

        public bool NeedCount { get; }

        public IDictionary<string, object> Parameters { get; } = new Dictionary<string, object>();

        public Func<IQueryable<TEntity>, IQueryable<TEntity>>? BaseQueryPlan { get; set; }
    }
}
